doseresNMA antidep/data.addOR.R

require(meta)
#** calculate OR and its SE
createORreference.fun=function(r,n)
{

  logOR=c(0)
  selogOR=c(NA)

  for(i in 2:c(length(n)))
  {
    calculate=metabin(r[i],n[i],r[1],n[1],sm="OR")
    logOR=c(logOR,calculate$TE)
    selogOR=c(selogOR,calculate$seTE)

  }
  return(cbind(logOR=logOR,selogOR=selogOR))
}

# add OR and its SE to the dataset
add_var <- function(data=antidep){
  data$studyid <- as.numeric(as.factor(data$studyid))
  logORmat <- sapply(unique(data$studyid),function(i) createORreference.fun(data$r[data$studyid==i],data$n[data$studyid==i]),simplify = FALSE)
  logORmat <- do.call(rbind,logORmat)
  data$logOR <- c(logORmat[,1])
  data$selogOR <- c(logORmat[,2])
  data$cov <- data$selogOR^2
  data
}
htx-r/doseresNMA documentation built on Jan. 28, 2021, 5:32 a.m.